﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ISO
{
    class Map
    {
        #region Variables
        enum Tiles_X
        { Template = 0, Grass = 1, Stone = 2 };
        enum Tiles_Y
        { Template = 0, Grass = 0, Stone = 0 };

        private Tile[,] _tiles;
        private double[]_current_tiles;
        private Point[,] _tile_coordinates;

        private int _starting_x = 480;
        private int _starting_y = 75;
        private int _num_visible_per_row = 20;
        private int _num_total_per_row = 100;
        #endregion

        #region Attributes
        public int Starting_X
        {
            get { return _starting_x;}
            set {_starting_x = value;}
        }
        public int Starting_Y
        {
            get {return _starting_y;}
            set {_starting_y = value;}
        }
        public int Num_Visible_Per_Row
        {
            get {return _num_visible_per_row;}
            set {_num_visible_per_row = value;}
        }
        public int Num_Total_Per_Row
        {
            get { return _num_total_per_row; }
            set {_num_total_per_row = value; }
        }
        public double[] CurrentTiles
        {
            get { return _current_tiles;}
            set {_current_tiles = value;}
        }
        public Point[,] TileCoordinates
        {
            get { return _tile_coordinates; }
        }
        public Tile[,] Tiles
        {
            get{return _tiles;}
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Generates a random basic map
        /// </summary>
        public Map()
        {
            _tiles = new Tile[_num_total_per_row,_num_total_per_row];
            _current_tiles = new double[2];
            _current_tiles[0] = 20; _current_tiles[1] = 20;
            _tile_coordinates = new Point[Num_Visible_Per_Row+1, Num_Visible_Per_Row+1];
            //creates a map full of grass tiles
            for (int _x = 0; _x < _num_total_per_row; _x++ )
            {
                for (int _y = 0; _y < _num_total_per_row; _y++ )
                {
                    _tiles[_x, _y] = new Tile((int)Tiles_X.Grass,(int)Tiles_Y.Grass);
                    
                }
            }

            //Generates the coordinates for the tiles
            for (int _x = 0; _x < _num_visible_per_row+1; _x++)
            {
                for (int _y = 0; _y < _num_visible_per_row+1; _y++)
                {
                    if (_y == 0)
                    {
                        _tile_coordinates[_x, _y].X = _starting_x + (_x) * _tiles[_x, _y].Width / 4;
                        _tile_coordinates[_x, _y].Y = _starting_y + (_x) * (_tiles[_x, _y].Height / 4 - 3);
                    }
                    else
                    {
                        _tile_coordinates[_x, _y].X = _tile_coordinates[_x, _y - 1].X - _tiles[_x, _y].Width / 4;
                        _tile_coordinates[_x, _y].Y = _tile_coordinates[_x, _y - 1].Y + (_tiles[_x, _y].Height / 4 - 3);
                    }
                }
            }
            //randomly fills the map with stone tiles
            for (int _z = 0; _z < (_num_total_per_row * _num_total_per_row) ; _z++)
            {
                int _rand_x = new Random().Next(0,_num_total_per_row);
                int _rand_y = new Random().Next(0, _num_total_per_row);
                _tiles[_rand_x, _rand_y] = new Tile((int)Tiles_X.Stone, (int)Tiles_Y.Stone);
            }
        }
        #endregion

        #region Methods
        #endregion
    }
}
